import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';

export default async function a004(fd: IFeidaoAiBrowserComponent, e: Event) {
	// todo
	// 每个DIV
	const answer = Array();
	const a = fd.data.node.querySelectorAll<HTMLDivElement>('[data-id="dataNo"]');
	for (let i = 0; i < a.length; i++) {
		const answ = get(fd, "valu" + (i + 1) + "");
		if (answ === undefined) {
			answer.push({ valu: "", no: "" });
		} else {
			answer.push(answ);
		}
	}
	// 答案
	const tr = fd.data.node.querySelectorAll(' input[type="hidden"]');
	const tru = Array.from(tr) as HTMLSelectElement[];
	const right_answer = Array();
	for (let i = 0; i < tru.length; i++) {
		right_answer.push(tru[i].value);
	}
	//    question_no
	const question_no = get(fd, 'no');
	// 试卷编号：
	const res = await nodejs<{ dt: { results: string, length: number } }>('employee-examination/zj-000003/s007', {});
	const paper_number = res.dt.results;
	// 总分
	const exam_score = get(fd, 'exam_score');
	// 选项
	const dt = get(fd, 'dt');
	const dt1 = get(fd, 'dt1');
	const dt2 = get(fd, 'dt2');
	// 考生编号：
	const candidate_no = get(fd, 'staff_no');
	// 考试编号：
	const exam_id = get(fd, 'exam_id');
	fire('zj-000005', 'a001', exam_id, candidate_no, question_no, paper_number, right_answer, answer, exam_score, dt, dt1, dt2);
}
